/**
 * 
 */
package edu.cmu.cs.webapp.ioms.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import edu.cmu.cs.webapp.ioms.dao.DataAccessException;
import edu.cmu.cs.webapp.ioms.dao.LogDAO;
import edu.cmu.cs.webapp.ioms.models.Client;
import edu.cmu.cs.webapp.ioms.models.IOMSPackage;
import edu.cmu.cs.webapp.ioms.models.LogEntry;
import edu.cmu.cs.webapp.ioms.models.OrderStatus;
import edu.cmu.cs.webapp.ioms.models.PurchaseOrder;

/**
 * @author Christian
 * 
 */
public class LogDAOImpl extends DAO implements LogDAO {

	@Override
	public List<LogEntry> retrieveLogs() throws DataAccessException {
		// TODO Auto-generated method stub
		Connection con = null;
		LogEntry log = null;
		List<LogEntry> loglst = new ArrayList<LogEntry>();
		try {
			con = getConnection();
			Statement stmt = con.createStatement();
			String sql = "select * from log";
			ResultSet rs = stmt.executeQuery(sql);
			while (rs.next()) {
				log = IOMSPackage.eINSTANCE.getIOMSFactory().createLogEntry();
				
				log.setLog_id(rs.getInt("log_id"));
				log.setLog_msg(rs.getString("log_msg"));
				log.setLog_type(rs.getString("log_type"));
				log.setUser(rs.getString("user"));
				log.setTime(rs.getDate("time"));

				loglst.add(log);
			}
			stmt.close();
			con.close();
		} catch (Exception e) {
			try {
				if (con != null)
					con.close();
			} catch (SQLException e2) { /* ignore */
			}
			throw new DataAccessException(e);
		}
		return loglst;
	}
}
